/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package crm.salesOrderProcessing.managedbean;

import java.io.IOException;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import crm.salesOrderProcessing.entity.SalesOrderEntity;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import scm.inventoryControl.session.stateless.InventoryControlSessionBean;

/**
 *
 * @author xhx
 */
@ManagedBean(name="salesOrderCreationResultManagedBean")
@ViewScoped
public class salesOrderCreationResultManagedBean {
private SalesOrderEntity salesOrder;
private String displayContent;
private String lastPage ="";

@EJB
InventoryControlSessionBean inventoryControlSessionBean;
    /** Creates a new instance of salesOrderCreationResultManagedBean */
    public salesOrderCreationResultManagedBean() {
    }
       
   
    
        public void initView(PhaseEvent event) {
        if (getSalesOrder() == null) { 
            setSalesOrder((SalesOrderEntity) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("salesOrder"));
            
        }   
           lastPage = FacesContext.getCurrentInstance().getExternalContext().getFlash().get("lastURL").toString(); 
           if(lastPage.contains("createSalesOrder"))
               displayContent = "The Sales Order is Successfully Created";
           if(lastPage.contains("confirmeSalesOrder"))
               displayContent = "The Sales Order is Confirmed";
           if(lastPage.contains("amendSalesOrder"))
               displayContent = "The Sales Order has been Successfully Amended";
           if(lastPage.contains("verifySalesOrder"))
               displayContent = "The Sales Order is Verified and thus is Successfully Created";
        
    }
        public void reserveInventory(){
//            inventoryControlSessionBean.reserveProduct(salesOrder);
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Inventory has Been reserved", ""));
        }
        public void viewDetail() throws IOException{
//    FacesContext.getCurrentInstance().getExternalContext().getFlash().put("lastURL", "viewAllPurchaseOrder.xhtml");
        FacesContext.getCurrentInstance().getExternalContext().getFlash().put("salesOrder", salesOrder);
        FacesContext.getCurrentInstance().getExternalContext().redirect("displaySalesOrder.xhtml");        
        }

    public SalesOrderEntity getSalesOrder() {
        return salesOrder;
    }

    public void setSalesOrder(SalesOrderEntity salesOrder) {
        this.salesOrder = salesOrder;
    }

    public String getDisplayContent() {
        return displayContent;
    }

    public void setDisplayContent(String displayContent) {
        this.displayContent = displayContent;
    }

    public String getLastPage() {
        return lastPage;
    }

    public void setLastPage(String lastPage) {
        this.lastPage = lastPage;
    }
}
